home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Sprite / c / LoadFiles < prev    next >
Text File  |  1994-10-06  |  3KB  |  66 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Sprite.LoadFiles.c
  12.     Author:  Sprite.LoadFile.c Copyright © 1994 Tim Browse
  13.              modifications for multiple files Copyright © 1994 Lee Atkinson
  14.     Version: 1.00 (25 Sep 1994)
  15.     Purpose: Allocate a sprite area and load any number of files into it.
  16. */
  17.  
  18. #include <stdarg.h>
  19. #include <stdlib.h>
  20.  
  21. #include "DeskLib:Core.h"
  22. #include "DeskLib:File.h"
  23. #include "DeskLib:Sprite.h"
  24.  
  25. extern sprite_area Sprite_LoadFiles(int nooffiles,...)
  26. /* loads any number of sprite files into a sprite area (allocated by malloc()),
  27.                                                   and returns a pointer to it */
  28. {
  29.  int          i,blksize=0;
  30.  sprite_area  sprarea;
  31.  va_list      argptr;
  32.  va_start(argptr,nooffiles); /* inititialise arguments pointer */
  33.  for (i=nooffiles;i;i--) blksize+=File_Size(va_arg(argptr,char *)); /* size of
  34.                                                                     all files */
  35.  blksize+=16; /* add room for extra header info & safety padding */
  36.  if ((sprarea=(sprite_area)malloc(blksize))==NULL) /* allocate memory */
  37.    {
  38.     va_end(argptr); /* if allocation failed, restore stack */
  39.     return NULL;    /*                            & return */
  40.    }
  41.  sprarea->areasize=blksize; /* initialise sprite area */
  42.  sprarea->firstoffset=16;
  43.  Sprite_InitArea(sprarea);
  44.  va_start(argptr,nooffiles); /* initialise stack pointer */
  45.  if (Sprite_Load(sprarea,va_arg(argptr,char *))) /* load 1st sprite file */
  46.    {
  47.     free(sprarea);  /* if load failed: deallocate;    */
  48.     va_end(argptr); /*                 restore stack; */
  49.     return NULL;    /*               & return         */
  50.    }
  51.  else
  52.      {
  53.       for (i=nooffiles-1;i;i--)
  54.          {
  55.           if (Sprite_Merge(sprarea,va_arg(argptr,char *))) /* merge the rest */
  56.             {
  57.              free(sprarea);  /* if a merge failed: deallocate;    */
  58.              va_end(argptr); /*                    restore stack; */
  59.              return NULL;    /*                 &  return         */
  60.             }
  61.          }
  62.      }
  63.  va_end(argptr); /* restore stack */
  64.  return sprarea; /* return */
  65. }
  66.